package 深入反射机制.反射方法Method.反编译Method.test01;

import test.UserService;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ResourceBundle;

public class ReflectTest01 {
    public static void main(String[] args) {
        StringBuffer s = new StringBuffer();

        ResourceBundle bundle = ResourceBundle.getBundle("invincibleConfiguration");
        Class userServiceClass = null;
        try {
            userServiceClass = Class.forName(bundle.getString("completeClassName"));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //Class userServiceClass = UserService.class;

        s.append(Modifier.toString(userServiceClass.getModifiers()) + " class " + userServiceClass.getSimpleName() +" {\n");

        Method[] methods = userServiceClass.getDeclaredMethods();
        for (Method method : methods){
            s.append("\t");
            s.append(Modifier.toString(method.getModifiers()));
            s.append(" ");
            s.append(method.getReturnType().getSimpleName());
            s.append(" ");
            s.append(method.getName());
            s.append(" (");
            Class[] parameterTypes = method.getParameterTypes();
            StringBuffer s2 = new StringBuffer();

            for (Class parameterType : parameterTypes){
                s2.append(parameterType.getSimpleName());
                s2.append(",");
            }
            String ss = new String(s2);
            if (ss.endsWith(",")){
                s2.deleteCharAt(s2.length()-1);
                s.append(s2);
            }

            s.append("){}\n");

        }
        s.append("}");
        System.out.println(s);
    }
}
